package app

import (
	"context"
	"github.com/jinzhu/copier"

	"web_server/internal/svc"
	"web_server/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type PoetLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewPoetLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PoetLogic {
	return &PoetLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *PoetLogic) Poet(req *types.PublicPathIdRequest) (*types.PoetResponse, error) {
	var result types.PoetResponse = types.PoetResponse{}
	if req.Id <= 0 {
		return &result, nil
	}
	findOne, err := l.svcCtx.MysqlClient.PoetModel.FindOne(l.ctx, req.Id)
	if err != nil {
		return nil, err
	}
	copyErr := copier.Copy(&result, &findOne)
	if copyErr != nil {
		return nil, copyErr
	}
	return &result, nil
}
